<template>
	<view>
		<view class="cu-list menu-avatar">
			<view class="cu-item">
				<view class="cu-avatar round lg" :style="'background-image:url(' + user_info.avatarUrl + ');'"></view>
				<view class="content">
					<view class="text-grey">{{ user_info.nickname ? user_info.nickname : '未设置昵称' }}</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">{{ user_info.phone ? user_info.phone : '未绑定手机号' }}</view>
					</view>
				</view>
				<view @click="bindPhone" class="action" style="width: 160upx;">{{ user_info.phone ? '更换手机号' : '绑定手机号' }}</view>
			</view>
			<view class="cu-list menu sm-border margin-top">
				<navigator class="cu-item arrow" url="/pages/reward/money">
					<view class="content">
						<text class="cuIcon-moneybag text-blue"></text>
						<text class="text-grey">我的收入</text>
					</view>
				</navigator>

				<navigator class="cu-item arrow" url="/pages/user/comment">
					<view class="content">
						<text class="cuIcon-markfill text-blue"></text>
						<text class="text-grey">对我的评价</text>
					</view>
				</navigator>

				<navigator  url="/pages/product/list" class="cu-item arrow">
					<view class="content">
						<text class="cuIcon-post text-blue"></text>

						<text class="text-grey">免费发布服务</text>
					</view>
				</navigator>

				<view class="cu-item arrow" @click="contactUs">
					<view class="content">
						<text class="cuIcon-dianhua text-blue"></text>
						<text class="text-grey">联系我们</text>
					</view>
					<view class="action"><text class="text-grey text-sm">4008374994</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import beeApp from '../../beeApp.js';
export default {
	data() {
		return {
			items: {},
			user_info: {
				tenement_type: [],
				community: {}
			},
			user_id: 0,
			userStatistics: {},
			mounted: 0,
			out_room_id: 0,
			community_id: 0
		};
	},
	onLoad() {
		this.fetchData();
	},

	onPullDownRefresh() {
		this.fetchData();
		uni.stopPullDownRefresh();
	},

	onShow: function() {
		var reload = beeApp.getPageData('pages/user/index', 'reload');
		if (reload == 1) {
			beeApp.setPageData('pages/user/index', { reload: 0 });
			this.fetchData();
		}
	},
	methods: {
		contactUs: function() {
			uni.makePhoneCall({
				phoneNumber: '4008374994'
			});
		},
		faceVerify: function() {
			if (beeApp.data.app_type != 'alipay') {
				beeApp.alert('请在支付宝中打开小程序完成实名认证!');
				return;
			}
			var bizId = beeApp.randomNum(10000000000,99999999999);
			console.log("bizId:",bizId);
			my.ap.faceVerify({
				bizId: bizId, // 业务流水号，商户自行生成，需要保证唯一性，不超过64位
				bizType: '2', // 业务场景参数，2 代表刷脸认证场景
				success: res => {
					console.log(res);
					my.alert({
						content: JSON.stringify(res)
					});
				},
				fail: res => {
					beeApp.alert(JSON.stringify(res))
				}
			});
		},
		bindPhone: function() {
			uni.navigateTo({
				url: '/pages/user/bindphone'
			});
		},
		fetchData: function fetchData() {
			var _this = this;
			this.getUserInfo();
			// _this.user_info = beeApp.getUserInfo();
		},

		getUserInfo: function() {
			var that = this;
			beeApp.api(
				'/api/user/info',
				{
					fields:
						'user_id,store_id,phone,nickname,phone,avatarUrl,last_update_time'
				},
				function(res) {
					if (res.code == 200) {
						that.user_info = res.data;
						that.out_room_id = res.data.out_room_id;
					}
				}
			);
		}
	}
};
</script>

<style>
.cu-list.menu > .cu-item .content .png {
	width: 40upx;
	height: 40upx;
}
</style>
